//
//  UIImage+Extension.swift
//  微博(Swift)
//
//  Created by V on 16/1/6.
//  Copyright © 2016年 V. All rights reserved.
//

import UIKit

extension UIImage{
    // 截屏
    class func getScreenShot() ->UIImage{
        let window = UIApplication.sharedApplication().keyWindow
        // 1. 开启图片类型的上下文
        UIGraphicsBeginImageContextWithOptions(window!.frame.size, false, 0)
        // 2. 画
        window?.drawViewHierarchyInRect(CGRect(origin: CGPointZero, size: window!.frame.size), afterScreenUpdates: false)
        // 3. 获取图片
        let image = UIGraphicsGetImageFromCurrentImageContext()
        // 4. 关闭上下文
        UIGraphicsEndImageContext()
        // 5. 返回
        return image
    }
}
